package com.suitsoft.bdms.entity.account;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springside.modules.utils.reflection.ConvertUtils;

import com.google.common.collect.Lists;
import com.suitsoft.bdms.entity.IdEntity;

/** 
 * 系统
 *@author Suineg
 */
@Entity
@Table(name = "ACCT_SYSTEM")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SubSystem extends IdEntity{
	/** 系统名称 */
	private String systemName;
	/** 角色 */
	private List<Role> roleList = Lists.newArrayList();
	
	public String getSystemName() {
		return systemName;
	}
	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}
	
//	@ManyToMany
//	@JoinTable(name = "ACCT_SYSTEM_ROLE", joinColumns = { @JoinColumn(name = "SYSTEM_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
//	@Fetch(FetchMode.SUBSELECT)
//	@OrderBy("id")
//	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@Transient
	public List<Role> getRoleList() {
		return roleList;
	}
	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}
	@Transient
	public String getRoleNames() {
		return ConvertUtils.convertElementPropertyToString(roleList, "name", ", ");
	}
	
	@SuppressWarnings("unchecked")
	@Transient
	public List<Long> getRoleIds(){
		return ConvertUtils.convertElementPropertyToList(roleList, "id");
	}
}

